home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / konq_iconviewwidget.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.9 KB  |  371 lines

  1. /*  This file is part of the KDE project
  2.     Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3.     Copyright (C) 2000, 2001, 2002 David Faure <david@mandrakesoft.com>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18. */
  19.  
  20. #ifndef __konq_iconviewwidget_h__
  21. #define __konq_iconviewwidget_h__
  22.  
  23. #include <kiconloader.h>
  24. #include <kiconview.h>
  25. #include <kurl.h>
  26. #include <qguardedptr.h>
  27. #include <kfileitem.h>
  28. #include <kio/jobclasses.h>
  29. #include <libkonq_export.h>
  30.  
  31. class KonqFMSettings;
  32. class KFileIVI;
  33. class KonqIconDrag;
  34. namespace KIO { class Job; }
  35.  
  36. /**
  37.  * A file-aware icon view, implementing drag'n'drop, KDE icon sizes,
  38.  * user settings, animated icons...
  39.  * Used by kdesktop and konq_iconview.
  40.  *
  41.  */
  42. class LIBKONQ_EXPORT KonqIconViewWidget : public KIconView
  43. {
  44.     Q_OBJECT
  45.     Q_PROPERTY( bool sortDirectoriesFirst READ sortDirectoriesFirst WRITE setSortDirectoriesFirst )
  46.     Q_PROPERTY( QRect iconArea READ iconArea WRITE setIconArea )
  47.     Q_PROPERTY( int lineupMode READ lineupMode WRITE setLineupMode )
  48.     Q_PROPERTY( QString url READ urlString WRITE setNewURL )
  49.  
  50.     friend class KFileIVI;
  51.  
  52. public:
  53.  
  54.     enum LineupMode { LineupHorizontal=1, LineupVertical, LineupBoth };
  55.  
  56.     /**
  57.      * Constructor
  58.      */
  59.     KonqIconViewWidget( QWidget *parent = 0L, const char *name = 0L, WFlags f = 0, bool kdesktop = FALSE );
  60.     virtual ~KonqIconViewWidget();
  61.  
  62.     /**
  63.      * Read the configuration and apply it.
  64.      * Call this in the inherited constructor with bInit=true,
  65.      * and in some reparseConfiguration() slot with bInit=false.
  66.      * Returns true if the font was changed (which means something has to
  67.      * be done so that the icon's texts don't run into each other).
  68.      * However Konq and KDesktop handle this differently.
  69.      */
  70.     bool initConfig( bool bInit );
  71.  
  72.     /**
  73.      * Set the area that will be occupied by icons. It is still possible to
  74.      * drag icons outside this area; this only applies to automatically placed
  75.      * icons.
  76.      */
  77.     void setIconArea( const QRect &rect );
  78.  
  79.     /**
  80.      * Reimplemented to make the slotOnItem highlighting work.
  81.      */
  82.     virtual void focusOutEvent( QFocusEvent * /* ev */ );
  83.  
  84.     /**
  85.      * Returns the icon area.
  86.      */
  87.     QRect iconArea() const;
  88.  
  89.     /**
  90.      * Set the lineup mode. This determines in which direction(s) icons are
  91.      * moved when lineing them up.
  92.      */
  93.     void setLineupMode(int mode);
  94.  
  95.     /**
  96.      * Returns the lineup mode.
  97.      */
  98.     int lineupMode() const;
  99.  
  100.     /**
  101.      * Line up the icons to a regular grid. The outline of the grid is
  102.      * specified by iconArea. The two length parameters are
  103.      * gridX and gridY.
  104.      */
  105.     void lineupIcons();
  106.  
  107.     /**
  108.      * Line up the icons to a regular grid horizontally or vertically.
  109.      *
  110.      * @param arrangement the arrangement to use (QIconView::LeftToRight
  111.      *        for a horizontal arrangement and QIconView::TopToBottom
  112.      *        for vertical)
  113.      */
  114.     void lineupIcons( QIconView::Arrangement arrangement );
  115.  
  116.     /**
  117.      * Sets the icons of all items, and stores the @p size
  118.      * This doesn't touch thumbnails, except if @p stopImagePreviewFor is set.
  119.      * Takes care of the grid, when changing the size.
  120.      *
  121.      * @param size size to use for the icons
  122.      * @param stopImagePreviewFor set to a list of mimetypes which should be made normal again.
  123.      * For instance "text/plain,image/wmf".
  124.      * Can be set to "*" for "all mimetypes" and to "image/"+"*" for "all images".
  125.      */
  126.     void setIcons( int size, const QStringList& stopImagePreviewFor = QStringList() );
  127.  
  128.     /**
  129.      * Called on databaseChanged
  130.      */
  131.     void refreshMimeTypes();
  132.  
  133.     int iconSize() { return m_size; }
  134.  
  135.     void calculateGridX();
  136.     /**
  137.      * The horizontal distance between two icons
  138.      * (whether or not a grid has been given to QIconView)
  139.      */
  140.     int gridXValue() const;
  141.  
  142.     /**
  143.      * Calculate the geometry of the fixed grid that is used to line up the
  144.      * icons, for example when using the lineupIcons() method.
  145.      *
  146.      * @param x
  147.      * @param y
  148.      * @param dx Cell width
  149.      * @param dy Cell height
  150.      * @param nx Number of columns
  151.      * @param ny Number of rows
  152.      */
  153.     void gridValues( int* x, int* y, int* dx, int* dy, int* nx, int* ny );
  154.  
  155.     /**
  156.      * Start generating the previews.
  157.      * @param ignored this parameter is probably ignored
  158.      * @param force if true, all files are looked at.
  159.      *    Otherwise, only those which are not a thumbnail already.
  160.      *
  161.      * @todo figure out the parameter meanings again
  162.      */
  163.     void startImagePreview( const QStringList &ignored, bool force );
  164.     void stopImagePreview();
  165.     bool isPreviewRunning() const;
  166.     // unused
  167.     void setThumbnailPixmap( KFileIVI * item, const QPixmap & pixmap );
  168.     void disableSoundPreviews();
  169.  
  170.     void setURL ( const KURL & kurl );
  171.     // ### KDE4: make const
  172.     const KURL & url() { return m_url; }
  173.     QString urlString() const { return m_url.url(); }
  174.     void setRootItem ( const KFileItem * item ) { m_rootItem = item; }
  175.  
  176.     /**
  177.      * Get list of selected KFileItems
  178.      */
  179.     KFileItemList selectedFileItems();
  180.  
  181.     void setItemColor( const QColor &c );
  182.     QColor itemColor() const;
  183.  
  184.     virtual void cutSelection();
  185.     virtual void copySelection();
  186.     virtual void pasteSelection();
  187.     virtual KURL::List selectedUrls(); // KDE4: remove virtual + add const
  188.     enum UrlFlags { UserVisibleUrls = 0, MostLocalUrls = 1 };
  189.     KURL::List selectedUrls( UrlFlags flags ) const; // KDE4: merge with above, default is == UserVisibleUrls
  190.     void paste( const KURL &url );
  191.  
  192.     bool sortDirectoriesFirst() const;
  193.     void setSortDirectoriesFirst( bool b );
  194.  
  195.     void setCaseInsensitiveSort( bool b );
  196.     bool caseInsensitiveSort() const;
  197.  
  198.     /**
  199.      * Cache of the dragged URLs over the icon view, used by KFileIVI
  200.      */
  201.     const KURL::List & dragURLs() { return m_lstDragURLs; }
  202.  
  203.     /**
  204.      * Reimplemented from QIconView
  205.      */
  206.     virtual void clear();
  207.  
  208.     /**
  209.      * Reimplemented from QIconView
  210.      */
  211.     virtual void takeItem( QIconViewItem *item );
  212.  
  213.     /**
  214.      * Reimplemented from QIconView to take into account iconArea.
  215.      */
  216.     virtual void insertInGrid( QIconViewItem *item );
  217.  
  218.     /**
  219.      * Reimplemented from QIconView to update the gridX
  220.      */
  221.     virtual void setItemTextPos( ItemTextPos pos );
  222.  
  223.     /**
  224.      * Give feedback when item is activated.
  225.      */
  226.     virtual void visualActivate(QIconViewItem *);
  227.  
  228.     bool isDesktop() const { return m_bDesktop; }
  229.  
  230.     /**
  231.      * Provided for KDesktop.
  232.      */
  233.     virtual void setWallpaper(const KURL&) { }
  234.  
  235.     bool maySetWallpaper();
  236.     void setMaySetWallpaper(bool b);
  237.  
  238.     void disableIcons( const KURL::List & lst );
  239.  
  240.     QString iconPositionGroupPrefix() const { return m_iconPositionGroupPrefix; }
  241.     QString dotDirectoryPath() const { return m_dotDirectoryPath; }
  242.  
  243.     void setPreviewSettings(const QStringList& mimeTypes);
  244.     const QStringList& previewSettings();
  245.     void setNewURL( const QString& url );
  246.  
  247. public slots:
  248.     /**
  249.      * Checks the new selection and emits enableAction() signals
  250.      */
  251.     virtual void slotSelectionChanged();
  252.  
  253.     void slotSaveIconPositions();
  254.  
  255.     void renameSelectedItem();
  256.     void renameCurrentItem();
  257.  
  258.     void slotToolTipPreview( const KFileItem *, const QPixmap & );  // ### unused - remove for KDE4
  259.     void slotToolTipPreviewResult() ;  // ### unused - remove for KDE4
  260.  
  261. signals:
  262.     /**
  263.      * For cut/copy/paste/move/delete (see kparts/browserextension.h)
  264.      */
  265.     void enableAction( const char * name, bool enabled );
  266.  
  267.     void dropped();
  268.     void imagePreviewFinished();
  269.  
  270.     void incIconSize();
  271.     void decIconSize();
  272.  
  273.     /**
  274.      * We need to track drag in icon views for the spring loading folders
  275.      */
  276.     void dragEntered( bool accepted );
  277.     void dragLeft();
  278.  
  279.     void dragMove( bool accepted );
  280.     /**
  281.      * Emited after the dropped() event. This way we know when the
  282.      * drag'n'drop is really finished.
  283.      */
  284.     void dragFinished();
  285.  
  286. protected slots:
  287.     virtual void slotDropped( QDropEvent *e, const QValueList<QIconDragItem> & );
  288.  
  289.     void slotItemRenamed(QIconViewItem *item, const QString &name);
  290.  
  291.     void slotIconChanged(int);
  292.     void slotOnItem(QIconViewItem *);
  293.     void slotOnViewport();
  294.     void slotStartSoundPreview();
  295.     void slotPreview(const KFileItem *, const QPixmap &);
  296.     void slotPreviewResult();
  297.  
  298.     void slotMovieUpdate( const QRect& rect );
  299.     void slotMovieStatus( int status );
  300.     void slotReenableAnimation();
  301.  
  302.     void slotAboutToCreate(const QPoint &pos, const QValueList<KIO::CopyInfo> &files);
  303.     void doubleClickTimeout();
  304.  
  305. protected:
  306.     virtual QDragObject *dragObject();
  307.     KonqIconDrag *konqDragObject( QWidget * dragSource = 0L );
  308.     bool mimeTypeMatch( const QString& mimeType, const QStringList& mimeList ) const;
  309.  
  310.     virtual void drawBackground( QPainter *p, const QRect &r );
  311.     /**
  312.      * r is the rectangle which you want to paint from the background.
  313.      * pt is the upper left point in the painter device where you want to paint
  314.      * the rectangle r.
  315.      */
  316.     virtual void drawBackground( QPainter *p, const QRect &r,
  317.                      const QPoint &pt );
  318.     virtual void contentsDragEnterEvent( QDragEnterEvent *e );
  319.     virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
  320.     virtual void contentsDragMoveEvent( QDragMoveEvent *e );
  321.     virtual void contentsDropEvent( QDropEvent *e );
  322.     virtual void contentsMousePressEvent( QMouseEvent *e );
  323.     virtual void contentsMouseReleaseEvent ( QMouseEvent * e );
  324.     virtual void contentsMouseMoveEvent( QMouseEvent *e );
  325.     virtual void backgroundPixmapChange( const QPixmap & );
  326.     virtual void wheelEvent( QWheelEvent* );
  327.     virtual void leaveEvent( QEvent *e );
  328.  
  329.     void readAnimatedIconsConfig();
  330.     void mousePressChangeValue();
  331.  
  332.     bool boostPreview() const;
  333.     int previewIconSize( int size ) const;
  334.     int largestPreviewIconSize( int size ) const;
  335.     bool canPreview( KFileItem* item );
  336.     void updatePreviewMimeTypes();
  337.  
  338. private:
  339.     KURL m_url;
  340.     const KFileItem * m_rootItem;
  341.  
  342.     KURL::List m_lstDragURLs;
  343.  
  344.     int m_size;
  345.  
  346.     /** Konqueror settings */
  347.     KonqFMSettings * m_pSettings;
  348.  
  349.     bool m_bMousePressed;
  350.     QPoint m_mousePos;
  351.  
  352.     QColor iColor;
  353.  
  354.     bool m_bSortDirsFirst;
  355.  
  356.     QString m_iconPositionGroupPrefix;
  357.     QString m_dotDirectoryPath;
  358.  
  359.     int m_LineupMode;
  360.     QRect m_IconRect;
  361.  
  362.     bool m_bDesktop;
  363.     bool m_bSetGridX;
  364.  
  365. private:
  366.     struct KonqIconViewWidgetPrivate *d;
  367.  
  368. };
  369.  
  370. #endif
  371.